<h1 class="crayons-title mb-3">Mods</h1>

<div class="mb-6 flex items-center flex-col m:flex-row">
  <ul class="crayons-navigation crayons-navigation--horizontal">
    <li>
      <a href="<%= admin_mods_path %>" class="crayons-navigation__item <%= "crayons-navigation__item--current" if params[:state].blank? %>">General Community</a>
    </li>
    <li>
      <a href="<%= admin_mods_path(state: :tag_moderator) %>" class="crayons-navigation__item <%= "crayons-navigation__item--current" if params[:state] == "tag_moderator" %>">Tag Mods</a>
    </li>
    <li>
      <a href="<%= admin_mods_path(state: :potential) %>" class="crayons-navigation__item <%= "crayons-navigation__item--current" if params[:state] == "potential" %>">Potential Mods</a>
    </li>
  </ul>

  <%= form_with url: admin_mods_path, method: :get, local: true, class: "flex mt-4 mx-auto m:ml-auto m:mt-0" do |f| %>
    <div class="mx-3">
      <%= f.text_field :search, value: params[:search], class: "crayons-textfield", aria: { label: "Search" } %>
      <%= f.hidden_field :state, value: params[:state] if params[:state].present? %>
    </div>
    <%= f.submit "Search", class: "crayons-btn" %>
  <% end %>
</div>
<% if @mods.empty? %>
    <div class="crayons-notice crayons-notice--warning">There are no mods matching your search criteria.</div>
<% else %>
  <%= paginate @mods, theme: "internal" %>

  <table class="crayons-table" width="100%">
    <thead>
      <tr>
        <th scope="col">ID</th>
        <th scope="col">Profile</th>
        <th scope="col">Comments</th>
        <th scope="col">Badges</th>
        <th scope="col">Last Comment</th>
        <% if params[:state] == "potential" %>
          <th scope="col">Action</th>
        <% end %>
      </tr>
    </thead>
    <tbody class="crayons-card">
      <% @mods.each do |mod| %>
        <tr>
          <td class="whitespace-nowrap"><%= mod.id %></td>
          <td><%= link_to mod.username, admin_user_path(mod.id) %></td>
          <td><%= mod.comments_count %></td>
          <td><%= mod.badge_achievements_count %></td>
          <td><%= time_ago_in_words mod.last_comment_at %> ago</td>
          <% if params[:state] == "potential" %>
            <td>
              <%= form_with model: [:admin, mod], url: admin_mod_path(mod.id), method: :patch, local: true do |f| %>
                <%= f.submit "Make Trusted", class: "crayons-btn crayons-btn--secondary js-add-to-mod-channel" %>
              <% end %>
            </td>
          <% end %>
        </tr>
      <% end %>
    </tbody>
  </table>

  <%= paginate @mods, theme: "internal" %>
<% end %>
